public class Test {
    //消失的数字：
    public int disappearingNumbers1(int[] nums) {
        int data = 0;
        for (int i = 0; i < nums.length; i++) {
            data ^= i;
            data ^= nums[i];
        }
        data ^= nums.length;
        return data;
    }

    public int disappearingNumbers2(int[] nums) {
        int data = nums.length;
        for (int i = 0; i < nums.length; i++) {
            data = data - nums[i] + i;//加减次序不能乱
        }
        return data;
    }


    //轮转数组
    public void rotatingArray1(int[] nums, int k) {
        k %= nums.length;
        for (int i = 0; i < k; i++) {
            int last = nums[nums.length - 1];
            for (int j = nums.length - 1; j >= 1; j--) {
                nums[j] = nums[j - 1];
            }
            nums[0] = last;
        }
    }

    public void rotatingArray2(int[] nums, int k) {
        k %= nums.length;
        rotating(nums, 0, nums.length - 1);
        rotating(nums, 0, k - 1);
        rotating(nums, k, nums.length - 1);
    }
    void rotating(int[] nums, int left, int right) {
        while (left < right) {
            int tmp = nums[left];
            nums[left] = nums[right];
            nums[right] = tmp;
            left++;
            right--;
        }
    }
}
